package com.qqtech.qquan.user.controller;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.qqtech.core.common.enums.YesNoEnum;
import com.qqtech.core.frame.model.Result;
import com.qqtech.core.frame.service.BaseService;
import com.qqtech.qquan.sys.controller.BaseAdminController;
import com.qqtech.qquan.user.model.UserSuggest;
import com.qqtech.qquan.user.model.UserSuggestReply;
import com.qqtech.qquan.user.service.UserSuggestReplyService;
import com.qqtech.qquan.user.service.UserSuggestService;

@Controller
@RequestMapping(value = "/user/suggest/replay")
public class UserSuggestReplyController extends BaseAdminController {
	@Resource
	private UserSuggestReplyService userSuggestReplyService;
	
	@Resource
	private UserSuggestService userSuggestService;

	@Override
	protected BaseService<UserSuggestReply> getBaseService() {
		return userSuggestReplyService;
	}

	@RequestMapping(value = "/add", method = RequestMethod.POST)
	@ResponseBody
	public Result add(UserSuggestReply userSuggestReply) {
		Result ret = new Result();
		UserSuggest userSuggest=userSuggestService.getById(userSuggestReply.getSuggestId());
		if(null==userSuggest){
			ret.addErr("该问题与建议已经被用户删除，无需回复。");
			return ret;
		}
		int addCount=userSuggestReplyService.insert(userSuggestReply);
		if(addCount>0){
			userSuggest.setIsReply(YesNoEnum.YES.getCode());
			userSuggestService.updateById(userSuggest);
		}
		return ret;
	}
	@RequestMapping(value = "/imgUpload", method = RequestMethod.GET)
	public String imgUpload(Model model) {
		return "/user/suggest/usersuggestreplay-imgUpload";
	}
}
